package demo2;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-09-16
 * Time: 23:43
 */
//饿汉模式
class Student2{
    private static Student2 student = new Student2();
    private Student2(){
        ;
    }
    public static Student2 getStudent(){
        return student;
    }
}
//懒汉模式
class Student3{
    private static volatile Student3 student3 = null;
    private static Object locker = new Object();
    private Student3(){}
    public static Student3 getStudent3(){
        if (student3 == null){
            synchronized (locker){
                if (student3 == null) {student3 = new Student3();}
            }
        }
        return student3;
    }
}
public class Test6 {
    public static void main(String[] args) {
        Student2 student2 = Student2.getStudent();//
    }
}
